package com.tavio.vaultboy.controller;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.math.MathUtils;

import com.tavio.vaultboy.element.Element;

public class MovementController extends Controller {
	
	public MovementController(int pX, int pY, Camera pCamera, ITextureRegion pControlBaseTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, Element element) {
		
		super(pX, pY, pCamera, pControlBaseTextureRegion, pVertexBufferObjectManager, element);
		
	}

	@Override
	protected void updateControlValue(float pTouchAreaLocalX, float pTouchAreaLocalY) {
		final Sprite controlBase = this.controlSprite;

		final float relativeX = MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth() - 0.5f;
		if(relativeX < 0) 
			this.controlValue = -1;
		else if(relativeX > 0)
			this.controlValue = 1;
		else	
			this.controlValue = 0;
	}

	
}
